//获取卖家信息
function getSellerInfo() {
  function doCallBack(res) {
    console.log(res);
    if (res.retcode == 0) {
      var result = JSON.parse(Base64.decode(res.data));
      console.log(result);
      if (result) {

        $("#companyName").val(result.company_name);
        $("#username").val(result.contact_name);
        $("#sex span").text(result.sex);
        if (result.sex == "男") {
          $("#sex")
            .addClass("male")
            .removeClass("famale");
        } else {
          $("#sex")
            .addClass("famale")
            .removeClass("male");
        }
        $("#sex").click(function (e) {
          e.preventDefault();
        })
        $("#telNumber").val(result.telephone);
        $("#email").val(result.email);
        $("#qqNumber").val(result.qq);
        $("#address").val(result.company_address);
        if (result.is_do == 1) {
          $(".container input").each(function () {
            $(this).attr("readonly", "readonly");
          })
			$('#submitBtn').css({
			  "display": "none"
			});
			$('#showresult').css({
			  "display": "block",
			  "width":"100%",
			  "textAlign":"center",
			  "color":"green"
			});

        }
        if (result.is_do == 0) {
          $('#submitBtn').css({
            "display": "block"
          });
        }
      } else {
        $('#submitBtn').css({
          "display": "block"
        });
      }
    }
if (res.retcode == 400){
  $('#submitBtn').css({
    "display": "block"
  });
}
  }
  $('#submitBtn').css({
	  "display": "block"
	});
  jAjax("account.getsellerinfo", doCallBack, {});
}
getSellerInfo();

//性别切换按钮的显示
$("#sex").click(function () {
  if ($(this).hasClass("famale")) {
    $(this)
      .addClass("male")
      .removeClass("famale");
    $(this)
      .children("span")
      .text("男");
  } else {
    $(this)
      .addClass("famale")
      .removeClass("male");
    $(this)
      .children("span")
      .text("女");
  }
});


$(".submitBtn").click(function () {
  var companyName = $("#companyName").val();
  var username = $("#username").val();
  var sex = $("#sex span").text();
  var telNumber = $("#telNumber").val();
  var email = $("#email").val();
  var qqNumber = $("#qqNumber").val();
  var address = $("#address").val();
  if (companyName == "") {
    DoAlert("公司名称不能为空");
    return false;
  } else if (username == "") {
    DoAlert("联系人姓名不能为空");
    return false;
  } else if (sex == "") {
    DoAlert("请选择性别");
    return false;
  } else if (telNumber == "" || !/^1\d{10}$/.test(telNumber)) {
    DoAlert("请填写正确的电话号码");
    return false;
  } else if (
    email == "" ||
    !/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(email)
  ) {
    DoAlert("请填写正确的邮箱");
    return false;
  } else if (qqNumber == "") {
    DoAlert("请填写正确的qq号码");
    return false;
  } else if (address == "") {
    DoAlert("请填写正确的公司地址");
    return false;
  } else {
    //调用卖家填写资料接口
    var sval = {
      company_name: companyName,
      contact_name: username,
      telephone: telNumber,
      sex: sex,
      email: email,
      qq: qqNumber,
      company_address: address
    };

    function doCallBack(res) {
      console.log(res);
      // DoAlert(res.message);
      if (res.retcode == 0) {
        DoAlert('提交成功');
      } else {
        DoAlert(res.message);
      }
    }
    jAjax("account.applyseller", doCallBack, sval);
  }
});

//解决键盘遮挡
resolveInput('#qqNumber');
resolveInput('#address');